#ifdef ACTORS_ENABLE
//logMessage(LOGLEVEL_DEBUG, "ACTORS", "", "");
unsigned long ACTORSPreviousMillis;
//Arrayaufbau FAN|LAMP1|LAMP2
int givenValue[] = {1,0,1};
int actualValue[] = {0,0,0};

/*************************************************************
 *
 * globals
 *
 *************************************************************/

void setupActors() {
	pinMode(LAMP1_PIN, OUTPUT);
	pinMode(LAMP2_PIN, OUTPUT);
	pinMode(FAN_PIN, OUTPUT);
	digitalWrite(LAMP1_PIN, LOW);
	digitalWrite(LAMP2_PIN, LOW);
	digitalWrite(FAN_PIN, LOW);
}

void processActorsDelay() {
	unsigned long tempCurrentMillis = millis();
	if((tempCurrentMillis - ACTORSPreviousMillis) > ACTORS_DELAY || ACTORSPreviousMillis == 0) {
		ACTORSPreviousMillis = tempCurrentMillis;
		_processActors();
	}
}

void setGivenValue(int anIndex, int aValue) {
	givenValue[anIndex] = aValue;
}

int getSystemLightOn(int aSystem) {
	if (aSystem == SYSTEM1) {
		return getStorageValue(TIMER_SYSTEM1_LIGHTON_FACILITY);
	}
	if (aSystem == SYSTEM2) {
		return getStorageValue(TIMER_SYSTEM2_LIGHTON_FACILITY);
	}
}

int getTimerDuration(int aSystem) {
	if (aSystem == SYSTEM1) {
		return getStorageValue(TIMER_SYSTEM1_LIGHTDURATION_FACILITY);
	}
	if (aSystem == SYSTEM2) {
		return getStorageValue(TIMER_SYSTEM2_LIGHTDURATION_FACILITY);
	}
}

/*************************************************************
 *
 * intern
 *
 *************************************************************/

void _processLamp(int tempSStatus, int aPin) {
	if (tempSStatus == 1) {
		digitalWrite(aPin, HIGH);
	}
	if (tempSStatus == 0) {
		digitalWrite(aPin, LOW);
	}
}

void _processActors() {
	_processLamp1();
	_processLamp2();
	_processFan();
}

void _processLamp1() {
	givenValue[LAMP1] = getStatusOfSystem(getSystemLightOn(SYSTEM1), getTimerDuration(SYSTEM1));
	if (actualValue[LAMP1] != givenValue[LAMP1]) {
		_processLamp(givenValue[LAMP1], LAMP1_PIN);
		actualValue[LAMP1] = givenValue[LAMP1];
	}
}

void _processLamp2() {
	givenValue[LAMP2] = getStatusOfSystem(getSystemLightOn(SYSTEM2), getTimerDuration(SYSTEM2));
	if (actualValue[LAMP2] != givenValue[LAMP2]) {
		_processLamp(givenValue[LAMP2], LAMP2_PIN);
		actualValue[LAMP2] = givenValue[LAMP2];
	}
}

void _processFan() {
	if (actualValue[FAN] != givenValue[FAN]) {
		digitalWrite(FAN_PIN, givenValue[FAN]);
		actualValue[FAN] = givenValue[FAN];
	}
}
#endif
